//
// Created by Administrator on 2024/1/31.
//
#include <vector>
#include <iostream>
#include <unordered_map>
using namespace std;


class Solution
{
public:
    int mostFrequent(vector<int>& nums, int key)
    {
        // 统计nums中每次出现key后紧跟的数字
        unordered_map<int, int> count;
        for (int i = 0; i < nums.size() - 1; ++i)
        {
            if (nums[i] == key)
            {
                count[nums[i + 1]]++;
            }
        }
        int ans = 0;
        int ans_count = 0;
        for (auto pair : count)
        {
            if (pair.second > ans_count)
            {
                ans = pair.first;
                ans_count = pair.second;
            }
        }
        return ans;
    }
};

int main()
{
    vector<int> nums{2, 2, 2, 2, 3};
    Solution s;
    cout << s.mostFrequent(nums, 2) << endl;
    return 0;
}
